<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

/*
| -------------------------------------------------------------------
| AssetController
| -------------------------------------------------------------------
| AssetController is a subclass of AuthenticatedController.
|
| AssetController echos static (non-php) resources if
| current user is logged in.
|
|
*/
 
require(APPPATH."libraries/auth/AuthenticatedController.php");
class AssetController extends AuthenticatedController {

   function AssetController()
	{
		parent::AuthenticatedController();
	}
	
    function get_asset($type)
    {
        $a = $this->uri->segment(3);
        $this->config->load('auth/AssetConfig', true);
        $config = $this->config->item('AssetConfig');
        $types = $config['types'];
        if (isset($config[$type]))
        {
            $path = @$config[$type][$a];
            $a_parts  = explode('.', $a);
            $ext = $a_parts[1];
    
            if ($a != '*' && file_exists($path))
            {
                $this->output->set_status_header('200');
                $this->output->set_header($types[$ext]);
                $this->output->set_output(file_get_contents($path));
            }
            else if (isset($config[$type]['*']) && is_dir($config[$type]['*']) && file_exists($config[$type]['*'] . '/' . $a))
            {
                $path = $config[$type]['*'] . '/' . $a;
                $this->output->set_status_header('200');
                $this->output->set_header($types[$ext]);
                $this->output->set_output(file_get_contents($path));
            }   
            else
            {
				show_404();
            }
        }
        else
        {
            $this->output->set_status_header('404');
            $this->output->set_header("Content-type: text/text");
            $this->output->set_output("Resource not found: $type\n");
        }
    }  
}




